package com.huiminpay.rocketmq.consumer.message;

import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(consumerGroup = "demo-consumer-group2", topic ="my_topic_obj" )
public class ConsumerSimpleObjDemo implements RocketMQListener<MessageExt> {



    @Override
    public void onMessage(MessageExt messageExt) {
        byte[] bodys = messageExt.getBody();
        System.out.println(new String(bodys));
        //处理消息
        //...

        System.out.println("开始处理消息....");
        //获取重试次数
        int reconsumeTimes = messageExt.getReconsumeTimes();
        if (reconsumeTimes>2) {
            //如果重试两次就不再重试了  使用另外的逻辑的单独处理
            //.....
            System.out.println("使用单独的逻辑处理消息或将消息保存到数据库");
            return;
        }

        if (1==1){
            throw new RuntimeException("消息处理失败");
        }
    }
}
